<?php

/**
 * Libro filter form base class.
 *
 * @package    universidad
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseLibroFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'titulo'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'tipo'            => new sfWidgetFormChoice(array('choices' => array('' => '', 'Digital' => 'Digital', 'Impreso' => 'Impreso'))),
      'direcciones'     => new sfWidgetFormFilterInput(),
      'titulo_original' => new sfWidgetFormFilterInput(),
      'traductor'       => new sfWidgetFormFilterInput(),
      'resumen'         => new sfWidgetFormFilterInput(),
      'tomo'            => new sfWidgetFormFilterInput(),
      'edicion'         => new sfWidgetFormFilterInput(),
      'ano_edicion'     => new sfWidgetFormFilterInput(),
      'ano_publicacion' => new sfWidgetFormFilterInput(),
      'paginas'         => new sfWidgetFormFilterInput(),
      'estado_fisico'   => new sfWidgetFormChoice(array('choices' => array('' => '', 'Delicado' => 'Delicado', 'Bueno' => 'Bueno', 'Nuevo' => 'Nuevo'))),
      'condicion'       => new sfWidgetFormChoice(array('choices' => array('' => '', 'Donacion' => 'Donacion', 'Prestamo' => 'Prestamo'))),
      'estado'          => new sfWidgetFormChoice(array('choices' => array('' => '', 'Prestado' => 'Prestado', 'Disponible' => 'Disponible', 'Reparacion' => 'Reparacion'))),
      'genero'          => new sfWidgetFormFilterInput(),
      'creador_id'      => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'autor_id'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Autor'), 'add_empty' => true)),
      'editorial_id'    => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Editorial'), 'add_empty' => true)),
      'lengua_id'       => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Lengua'), 'add_empty' => true)),
      'palabra_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Palabra')),
    ));

    $this->setValidators(array(
      'titulo'          => new sfValidatorPass(array('required' => false)),
      'tipo'            => new sfValidatorChoice(array('required' => false, 'choices' => array('Digital' => 'Digital', 'Impreso' => 'Impreso'))),
      'direcciones'     => new sfValidatorPass(array('required' => false)),
      'titulo_original' => new sfValidatorPass(array('required' => false)),
      'traductor'       => new sfValidatorPass(array('required' => false)),
      'resumen'         => new sfValidatorPass(array('required' => false)),
      'tomo'            => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'edicion'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'ano_edicion'     => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'ano_publicacion' => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'paginas'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'estado_fisico'   => new sfValidatorChoice(array('required' => false, 'choices' => array('Delicado' => 'Delicado', 'Bueno' => 'Bueno', 'Nuevo' => 'Nuevo'))),
      'condicion'       => new sfValidatorChoice(array('required' => false, 'choices' => array('Donacion' => 'Donacion', 'Prestamo' => 'Prestamo'))),
      'estado'          => new sfValidatorChoice(array('required' => false, 'choices' => array('Prestado' => 'Prestado', 'Disponible' => 'Disponible', 'Reparacion' => 'Reparacion'))),
      'genero'          => new sfValidatorPass(array('required' => false)),
      'creador_id'      => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'autor_id'        => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Autor'), 'column' => 'id')),
      'editorial_id'    => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Editorial'), 'column' => 'id')),
      'lengua_id'       => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Lengua'), 'column' => 'id')),
      'palabra_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Palabra', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('libro_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addPalabraListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LibroPalabra LibroPalabra')
      ->andWhereIn('LibroPalabra.palabra_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Libro';
  }

  public function getFields()
  {
    return array(
      'id'              => 'Number',
      'titulo'          => 'Text',
      'tipo'            => 'Enum',
      'direcciones'     => 'Text',
      'titulo_original' => 'Text',
      'traductor'       => 'Text',
      'resumen'         => 'Text',
      'tomo'            => 'Number',
      'edicion'         => 'Number',
      'ano_edicion'     => 'Number',
      'ano_publicacion' => 'Number',
      'paginas'         => 'Number',
      'estado_fisico'   => 'Enum',
      'condicion'       => 'Enum',
      'estado'          => 'Enum',
      'genero'          => 'Text',
      'creador_id'      => 'Number',
      'autor_id'        => 'ForeignKey',
      'editorial_id'    => 'ForeignKey',
      'lengua_id'       => 'ForeignKey',
      'palabra_list'    => 'ManyKey',
    );
  }
}
